<template>
  <smart-form ref="search_from" :model="form_data" :object="object" :url="''">
    <smart-form-layout label="内容" name="content">
      <smart-text-view type="textarea" name="content"></smart-text-view>
    </smart-form-layout>
    <smart-form-layout label="配置类型" name="format">
      <smart-radio-group name="format" :options="variable_type_dic"></smart-radio-group>
    </smart-form-layout>
  </smart-form>
</template>

<script>
import SubjectAPI from "../../../components/subject/subject-api";

export default {
    components: {},
    props: {
        // 当前需要操作的数据对象
        object: {type: Object, default: undefined},
        // 成功回调，通常是刷新数据表格
        onSucceed: {type: Function, default: undefined}
    },
    data() {
        return {
            // 当前操作的数据
            row_data: undefined,
            // 字典
            variable_type_dic: [],
            // form-data start 表单数据对象模型
            form_data: [
                {
                    name: 'id', label: 'ID', value: ''
                    , rules: [
                        {required: true, message: '[ID]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'userId', label: '归属账号', value: ''
                    , rules: [
                        {required: true, message: '[归属账号]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'name', label: '名称', value: ''
                    , rules: [
                        {required: true, message: '[名称]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'label', label: '标签', value: ''
                    , rules: [
                        {required: true, message: '[标签]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'content', label: '内容', value: ''
                    , rules: [
                        {required: true, message: '[内容]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 65535, message: '最多65535字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'description', label: '简介', value: ''
                    , rules: [
                        {required: true, message: '[简介]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 65535, message: '最多65535字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'format', label: '配置类型', value: ''
                    , rules: [
                        {required: true, message: '[配置类型]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'disabled', label: '禁用', value: ''
                },
                {
                    name: 'readonly', label: '只读', value: ''
                },
                {
                    name: 'gmtCreate', label: '创建日期', value: ''
                },
                {
                    name: 'gmtModified', label: '修改日期', value: ''
                },
            ]
            // form-data end
            , default_data: {}
        }
    },
    created() {
        SubjectAPI.queryVariableTypeDic().then(list => {
            this.variable_type_dic = list;
        })
    },
    methods: {
        /**
         * submit form
         */
        submitForm: function () {
            this.$refs.search_from.validate(valid => {
                if (valid) {
                    Layers.ajax({
                        url: 'dev/device/info',
                        method: 'POST',
                        params: this.form_data
                    }).then((ret) => {
                        if (ret.code === 0) {
                            this.onSucceed();
                            Layers.succeed("操作成功！");
                        }
                    });
                } else {
                    this.$layers.warn('表单包含无效字段！');
                }
            });
        }

        /**
         * reset form
         */
        , resetForm: function () {
            this.$refs.search_from.resetFields();
        }


        /**
         * input change event
         */
        , onchange: function (val) {
            console.log(val);
        }


        /**
         * 重置表单
         */
        , reset: function () {
            Layers.recover(this.default_data, this.form_data);
        }

        /**
         * 设置行级数据
         * @param row 行级数据
         */
        , setRowData: function (row) {

        }
    }
}
</script>